<template>
	<!-- 居民信息 -->
	<view class="building-container">
		<view class="building-top">
			<view class="top-search">
				<u-search placeholder="搜索" shape="square" v-model="keywords" @search="handleSearch" @custom="handleSearch"></u-search>
			</view>
			<view class="top-bottom">
				<view class="top-2" @click="handleSelect"><text>网格:</text>{{ address }}
					<u-icon name="arrow-down" color="#007AFF" size="24"></u-icon>
				</view>
				<view class="top-2" @click="show2=true">
					{{ danyuan }}
					<u-icon name="arrow-down" color="#007AFF" size="24"></u-icon>
				</view>
			</view>
		</view>
		<view class="building-content">
			<view class="content-item" v-for="(item,index) in ResidentList" :key="index" @click="handleGoHourseInfo(item)">
				<view class="item-left">
					<image v-if="item.userImage==''|| item.userImage==null" src="../../../static/infor/ren.png"></image>
					<image v-else :src="item.userImage"></image>
				</view>
				<view class="item-right">
					<view class="right-top">
						<view class="top-left">
							<view class="left1">{{ item.userRealname }}</view>
							<view class="left2">
								<image mode="widthFix" v-if="item.userSex == 2" src="../../../static/infor/nv.png"></image>
								<image mode="widthFix" v-else src="../../../static/infor/nan.png"></image>
							</view>
						</view>
						<view class="top-right">
							<view class="top-right">{{ item.userPolitical_dictText || '暂无资料' }}</view>
							<view class="top-right">{{ item.userNation_dictText || '汉族' }}</view>
						</view>
					</view>
					<view class="right-bottom">年龄:{{ item.userAge || '暂无资料' }}</view>
				</view>
			</view>
		</view>

		<u-select v-model="show" mode="single-column" :list="floorList" value-name="id" label-name="fullName"
			@confirm="confirm"></u-select>
		<u-select v-model="show2" mode="single-column" :list="HouseList" value-name="id" label-name="name"
			@confirm="confirm2"></u-select>
		<!-- 列选择器 -->
		<u-popup v-model="selectShow" mode="bottom">
			<view class="gridcontent">
				<view class="item">
					<text @click="TCShow=true">通川区</text>
					<view class="item1" v-for="(item,index) in selectList" :key="index" v-if="TCShow">
						<view class="item2" @click="confirmGird(item.depart.departName,item.depart.id)">
							<text @click="TCShow2=true">{{ item.depart.departName }}</text>
							<view class="item3" v-for="(it,i) in item.son" :key="i" v-if="TCShow2" @click="confirmGird(it.depart.departName,it.depart.id)">
								<text @click="TCShow3=true">{{ it.depart.departName }}</text>
								<view class="item4" v-for="(it2,i2) in it.son" :key="i2" v-if="TCShow3" @click="confirmGird(it2.depart.departName,it2.depart.girdId)">
									{{ it2.depart.departName }}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		<u-loadmore :status="status" icon-color="#007AFF" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectShow:false,
				selectList: [],
				TCShow:false,
				TCShow2:false,
				TCShow3:false,
				address: '塔沱社区',
				
				pageNo:1,
				pageSize:10,
				status: 'loading',
				tolnum:0,
				
				HouseList: [],
				floorList: [],
				ResidentList: [],
				floorId: '',
				houseId: '',
				keywords: '',
				list: [{
					img: '../../../static/icon/gongzuotai.png',
					title: '卡啦啊说看看书',
					address: '解放路社区第一网格',
					type: '汉族'
				}],
				lou: '选择楼层',
				danyuan: '选择房屋',
				show: false,
				show2: false,
				
			}
		},
		onLoad(options) {
			// console.log(options)
		},
		mounted() {
			this.getFloor()
			this.getGridList()
			this.getHomeList()
			this.getResident()
		},
		// 上拉
		onReachBottom() {
			this.pageNo = this.pageNo + 1
			if(this.pageNo > this.tolnum) {
				return this.status = 'nomore'
			}
			this.getResident()
		},
		// 下拉
		onPullDownRefresh() {
			this.ResidentList=[]
			this.pageNo = 1;
			this.status = 'loading'
			this.getResident()
			setTimeout(function () {
			    uni.stopPullDownRefresh();
			}, 1500);
		},
		methods: {
			// 获取网格
			getGridList() {
				this.$u.api.getGridList()
					.then(res => {
						if (res.code == 200) {
							this.selectList = res.result.son
						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			confirmGird(data,id) {
				this.selectShow = false
				this.address = data
			},
			// 列选择器
			handleSelect() {
				this.selectShow = true
			},
			
			//搜索
			handleSearch() {
				if(this.keywords.trim().length == 0) {
					return uni.showToast({
						title:'请输入关键字',
						icon:'none'
					})
				}
				let params = {
					keywords:this.keywords
				}
				this.$u.api.getUserByType(params)
					.then(res => {
						console.log(res)
						if(res.code == 200) {
							this.ResidentList = []
							res.result.records.forEach(item => {
								this.ResidentList.push(item)
							})
						}
					})
					.catch(err => {
						console.log(err)
						uni.showToast({
							title:'搜索失败',
							icon:'none'
						})
					})
			},
			
			
			onNavigationBarButtonTap() {
				uni.navigateTo({
					url: 'Population-add/Population-add'
				})
			},
			handleGoHourseInfo(item) {
				uni.setStorageSync("info", JSON.stringify(item))
				uni.navigateTo({
					url: 'Population-info/Population-info'
				})
			},
			confirm(e) {
				this.floorId = e[e.length - 1].value
				this.lou = e[e.length - 1].label
			},
			confirm2(e) {
				this.houseId = e[e.length - 1].value
				this.danyuan = e[e.length - 1].label
			},
			// 房屋
			getHomeList() {
				this.$u.api.getOwnHomeList({
						quartersId: this.floorId
					})
					.then(res => {
						// console.log('房屋', res)
						if (res.code == 200) {
							if (res.result.length > 0) {
								this.HouseList = res.result
								this.houseId = res.result[0].id
							}

						}
					})
					.catch(err => {
						console.log(err)
					})
			},
			// 楼层
			getFloor() {
				this.$u.api.getFloor()
					.then(res => {
						// console.log('楼层', res)
						if (res.code == 200) {
							this.floorList = res.result
							this.floorId = res.result[0].id
							this.getHomeList();
						}
					})
					.catch(err => {
						console.log(err)
					})

			},
			// 人口
			getResident() {
				let params = {
					pageNo:this.pageNo,
					pageSize:this.pageSize
				}
				this.$u.api.getResident(params)
					.then(res => {
						// console.log(res)
						res.result.records.forEach(item => {
							this.ResidentList.push(item)
						})
					})
					.catch(err => {
						console.log(err)
						this.status = 'nomore'
						uni.showToast({
							icon:'none',
							title:'请稍后再试'
						})
					})
			}
		},

	}
</script>

<style lang="scss" scoped>
	.building-container {
		background-color: #f5f6f7;
		min-height: 100vh;
		padding-top: 180rpx;
		.gridcontent{
			height: 40vh;
			width: 100%;
			padding: 20rpx;
			color: #333;
			font-size: 27rpx;
			text-align: left;
			.item{
				width: 100%;
				padding: 5rpx 40rpx;
				overflow-y: auto;
				.item1{
					padding: 5rpx 40rpx;
					.item2{
						padding: 5rpx 40rpx;
						.item3{
							padding: 5rpx 40rpx;
							.item4{
								padding: 5rpx 40rpx;
								
							}
						}
					}
				}
			}
		}
		.building-top {
			background-color: #fff;
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			height: 170rpx;
			box-shadow: 3px 3px 3px #eee;
			padding: 20rpx;
			z-index: 10;
			.top-bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;

			}

			.top-2 {
				color: #007AFF;
				font-size: 25rpx;
				margin-top: 30rpx;
				width: 50%;
				text-align: left;

				text {
					color: #000;
					display: inline-block;
					margin-right: 10rpx;
				}
			}
		}

		.building-content {
			padding: 20rpx;

			.content-item {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 10rpx;
				padding: 20rpx;
				height: 170rpx;

				.item-left {
					width: 150rpx;
					height: 150rpx;
				}

				.item-right {
					display: flex;
					justify-content: space-between;
					align-items: flex-start;
					flex-direction: column;
					margin-left: 20rpx;
					height: 100%;
					width: 540rpx;

					.right-top {
						display: flex;
						justify-content: space-between;
						align-items: center;
						width: 100%;

						.top-left {
							display: flex;
							justify-content: center;
							align-items: center;

							.left1 {
								color: 000;
								margin-right: 20rpx;
							}

							.left2 {
								width: 20rpx;
								image {
									width: 100%;
								}
							}
						}

						.top-right {
							color: #007AFF;
							background-color: #f4f1f1;
							padding: 3rpx 10rpx;
							border-radius: 10rpx;
							font-size: 22rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							margin-right: 10rpx;
						}
					}

					.right-bottom {
						color: #999;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>
